package com.ncp.model.biz.registerlogin;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.jstl.sql.Result;

import com.ncp.model.dao.DB;
import com.ncp.model.dao.DbConnection;

public class adminLoginBiz {

	/*
	 * 判断是否已经为注册用户
	 * */
	private DB common=new DB();
	private PreparedStatement pstmt=null;
	private Connection conn=null;
	private ResultSet rs=null;
	
	public int isAdmin(String adminLoginName){
		/***根据不同的返回值，判断对应的状态信息
		 * -1代表没有此管理员。
		 * 1代表用户是管理员 ****/
		int result = -1;
		String sql = "select AdminLoginName from ADMINBASIC where AdminLoginName='"+adminLoginName+"'";
		try {
			conn=DbConnection.getConnByDataSource();
			pstmt=conn.prepareStatement(sql);
			rs=pstmt.executeQuery();
			if(rs.next()){
				result=1;
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally{
			common.closeSQL(conn, pstmt);
		}
		return result;
	}
	/**
	 * 判断管理员密码是否正确
	 * @param userLoginName
	 * @param passWord
	 * @return
	 */
	public int checkAdminPsd(String adminLoginName,String passWord){
		/***判断管理员密码是否输入正确
		 * -1代表密码错误。
		 * 1代表密码输入正确****/
		int result = -1;
		String sql="select AdminLoginName,PassWord from USERBASIC where AdminLoginName=? ";
		common.setSql(sql);
		common.setConn(DbConnection.getConnByDataSource());
		List<Object> list=new ArrayList<Object>();
		list.add(0,adminLoginName);
		//list.add(1,passWord);
		common.setList(list);
		Result rs = common.executeQuery();
		if(rs.getRows()[0].get("PassWord").toString().equals(passWord)){
			result = 1;
		}else{
			result = -1;
		}
		return result;
	}
}
